﻿using System;

// 定义形状接口
interface IShape
{
    double CalculateArea();
}

// 定义抽象类 Shape
abstract class Shape
{
    public abstract bool IsValid();
}

// 长方形类
class Rectangle : Shape, IShape
{
    public double Width { get; set; }
    public double Height { get; set; }

    public override bool IsValid()
    {
        return Width > 0 && Height > 0;
    }

    public double CalculateArea()
    {
        return Width * Height;
    }
}

// 正方形类
class Square : Shape, IShape
{
    public double SideLength { get; set; }

    public override bool IsValid()
    {
        return SideLength > 0;
    }

    public double CalculateArea()
    {
        return SideLength * SideLength;
    }
}

// 三角形类
class Triangle : Shape, IShape
{
    public double Base { get; set; }
    public double Height { get; set; }

    public override bool IsValid()
    {
        return Base > 0 && Height > 0;
    }

    public double CalculateArea()
    {
        return 0.5 * Base * Height;
    }
}

class Program
{
    static void Main()
    {
        Rectangle rectangle = new Rectangle { Width = 5, Height = 10 };
        if (rectangle.IsValid())
        {
            Console.WriteLine($"长方形面积为: {rectangle.CalculateArea()}");
        }

        Square square = new Square { SideLength = 5 };
        if (square.IsValid())
        {
            Console.WriteLine($"正方形面积为: {square.CalculateArea()}");
        }

        Triangle triangle = new Triangle { Base = 4, Height = 6 };
        if (triangle.IsValid())
        {
            Console.WriteLine($"三角形面积为: {triangle.CalculateArea()}");
        }
        Console.ReadKey();
    }
}